package com.kb.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.apache.log4j.Logger;

import com.car.util.ConnectionPool;
import com.kb.bean.AutoKBEntity;

public class AutoKBDAO {
	static Logger logger = Logger.getLogger(AutoKBDAO.class.getName());
	private static String hostIP = "localhost";

	public boolean addCarKB(AutoKBEntity kb) {
		boolean isInsert = false;
		Connection conn = ConnectionPool.getConnection("autohome", "root", "zhouzhou100428", hostIP);
		PreparedStatement ps = null;
		String sql = "REPLACE INTO qczj_kb(kb_kbid, kb_ppid, kb_cxid, kb_yhmc, kb_yhid, kb_plrq, kb_gmdd, kb_gmqy, kb_jxs, kb_kj,kb_dl, kb_ck, kb_yh, kb_ssx, kb_wg, kb_ns, kb_xjb, kb_plnr, kb_plcd, kb_gmsj, kb_gmjg, kb_syyh,kb_lc, kb_zcs, kb_lls, kb_pls, kb_ztsl, kb_zqsj,kb_gcmd) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		try {
			ps = conn.prepareStatement(sql);
			ps.setInt(1, kb.getKb_kbid());
			ps.setInt(2, kb.getKb_ppid());
			ps.setInt(3, kb.getKb_cxid());
			ps.setString(4, kb.getKb_yhmc());
			ps.setInt(5, kb.getKb_yhid());
			ps.setDate(6, kb.getKb_plrq());
			ps.setString(7, kb.getKb_gmdd());
			ps.setString(8, kb.getKb_gmqy());
			ps.setString(9, kb.getKb_jxs());
			ps.setFloat(10, kb.getKb_kj());
			ps.setFloat(11, kb.getKb_dl());
			ps.setFloat(12, kb.getKb_ck());
			ps.setFloat(13, kb.getKb_yh());
			ps.setFloat(14, kb.getKb_ssx());
			ps.setFloat(15, kb.getKb_wg());
			ps.setFloat(16, kb.getKb_ns());
			ps.setFloat(17, kb.getKb_xjb());
			ps.setString(18, kb.getKb_plnr());
			ps.setInt(19, kb.getKb_plcd());
			ps.setDate(20, kb.getKb_gmsj());
			ps.setFloat(21, kb.getKb_gmjg());
			ps.setFloat(22, kb.getKb_syyh());
			ps.setInt(23, kb.getKb_lc());
			ps.setInt(24, kb.getKb_zcs());
			ps.setInt(25, kb.getKb_lls());
			ps.setInt(26, kb.getKb_pls());
			ps.setInt(27, kb.getKb_ztsl());
			ps.setDate(28, kb.getKb_zqsj());
			ps.setString(29, kb.getKb_gcmd());
			isInsert = ps.execute();
			logger.info("CxID=" + kb.getKb_cxid() + " KbID=" + kb.getKb_kbid() + " 插入成功");
		} catch (SQLException e) {
			e.printStackTrace();
			logger.error("CxID=" + kb.getKb_cxid() + " KbID=" + kb.getKb_kbid() + " 插入失败");

		} finally {
			ConnectionPool.close(ps, conn);
		}
		return isInsert;
	}

	public void insertGCYT(int carid, int kb_kbid, int kb_gcmd) {
		Connection conn = ConnectionPool.getConnection("autohome", "root", "zhouzhou100428", hostIP);
		PreparedStatement ps = null;
		String sql = "REPLACE INTO qczj_kb_gcyt(gcyt_ppid,gcyt_kbid,gcyt_yt) VALUES(?,?,?)";
		try {
			ps = conn.prepareStatement(sql);
			ps.setInt(1, carid);
			ps.setInt(2, kb_kbid);
			ps.setInt(3, kb_gcmd); 
			ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			ConnectionPool.close(ps, conn);
		}
	}
}
